// pages/codePickUp/codePickUp.js
const app = getApp()
var api = require('../../../utils/api.js')
var util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.flag=="true"){
      this.setData({
        flag: "isFlag"
      })
    }else{
      this.setData({
        flag: "onFlag"
      })
    }
      
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (this.data.flag == "isFlag") {
      this.getCode();
    }
  },
  getCode: function () {
    var that = this;
    api.POST({
      params: {},
      url: app.globalData.base_url + 'winecabinet/createCodeImg',
      success: function (res) {
        if (util.isEmpty(res.data.code)) {
          that.setData({
            codeImg: res.data.data.result.code_img
          })
        }
      },
      fail: function (fail) {
        util.showError("网络错误，请检查网络");

      }
    })
  },
  cancel:function(){
    wx.switchTab({
      url: '/wine/pages/wineNew/wineNew'
    });
  }
})